package per.ethan.springboot.example.controller;

import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;
import per.ethan.springboot.example.entity.ScheduleJob;
import per.ethan.springboot.example.job.HelloJob;
import per.ethan.springboot.example.service.ScheduleService;

/**
 * @author Ethan
 * @date 2020/06/07 17:03
 */
@RestController
@RequiredArgsConstructor(onConstructor_ = @Autowired)
public class QuartzController {

    private final ScheduleService scheduleService;

    @PostMapping
    public String addJob(@RequestBody ScheduleJob scheduleJob) {
        scheduleJob.setJobClass(HelloJob.class);
        scheduleService.addJob(scheduleJob);
        return "添加成功";
    }

    @PutMapping
    public String updateJob(@RequestBody ScheduleJob scheduleJob) {
        scheduleJob.setJobClass(HelloJob.class);
        scheduleService.updateJob(scheduleJob);
        return "修改成功";
    }

    @PostMapping(value = "/resume")
    public String resumeJob(@RequestBody ScheduleJob scheduleJob) {
        scheduleService.resumeJob(scheduleJob);
        return "恢复成功";
    }

    @PostMapping(value = "/pause")
    public String pauseJob(@RequestBody ScheduleJob scheduleJob) {
        scheduleService.pauseJob(scheduleJob);
        return "暂停成功";
    }

}
